<?php

namespace app\adminapi\validate\game;

use app\common\model\game\Software;
use app\common\validate\BaseValidate;

/**
 * 软件管理验证
 * Class SoftwareValidate
 * @package app\adminapi\validate\game
 */
class SoftwareValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'require|checkSoftware',
        'name' => 'require|length:1,255',

        //'is_show' => 'require|in:0,1',
    ];

    protected $message = [
        'id.require' => '软件id不能为空',
        'name.require' => '软件名称不能为空',
        'name.length' => '软件名称长度须在1-255位字符',
    ];

    /**
     * @notes  添加场景
     * @return SoftwareValidate
     * @date 2022/2/22 9:57
     */
    public function sceneAdd()
    {
        return $this->remove(['id'])
            ->remove('id','require|checkSoftware');
    }

    /**
     * @notes  详情场景
     * @return SoftwareValidate
     * @date 2022/2/22 10:15
     */
    public function sceneDetail()
    {
        return $this->only(['id']);
    }

    /**
     * @notes  更改状态场景
     * @return SoftwareValidate
     * @date 2022/2/22 10:18
     */
    public function sceneStatus()
    {
        return $this->only(['id', 'is_show']);
    }

    public function sceneEdit()
    {
    }

    /**
     * @notes  删除场景
     * @return SoftwareValidate
     * @date 2022/2/22 10:17
     */
    public function sceneDelete()
    {
        return $this->only(['id']);
    }

    /**
     * @notes  检查指定软件是否存在
     * @param $value
     * @return bool|string
     * @date 2022/2/22 10:11
     */
    public function checkSoftware($value)
    {
        $article = Software::findOrEmpty($value);
        if ($article->isEmpty()) {
            return '软件不存在';
        }
        return true;
    }

}